﻿<Application x:Class="IsDirtyAndIsInvalidExample.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:presentationCore="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
             StartupUri="View\MainWindow.xaml">
    <Application.Resources>
        <presentationCore:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Style x:Key="ChangeNotificationText" TargetType="{x:Type TextBlock}">
            <Setter Property="Visibility" Value="Collapsed" />
            <Setter Property="Foreground" Value="Red" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="FontSize" Value="20" />
            <Setter Property="Text" Value="!" />
            <Setter Property="FontSize" Value="20" />
            <Setter Property="FontFamily" Value="Arial Rounded MT" />
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <RotateTransform Angle="20" />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsDirty}" Value="True">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="Button" x:Key="ActionButton">
            <Setter Property="Cursor" Value="Hand" />
        </Style>
        <Style TargetType="Button" x:Key="AddButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Add.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="Button" x:Key="CancelButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Cancel.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="Button" x:Key="EditButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Edit.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="Button" x:Key="RemoveButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Remove.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="Button" x:Key="SaveButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Visibility" Value="Collapsed" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Save.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsDirty}" Value="True" />
                        <Condition Binding="{Binding IsInvalid}" Value="False" />
                        <Condition Binding="{Binding IsInvalidWithin}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="Visibility" Value="Visible" />
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsDirtyWithin}" Value="True" />
                        <Condition Binding="{Binding IsInvalid}" Value="False" />
                        <Condition Binding="{Binding IsInvalidWithin}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="Visibility" Value="Visible" />
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="Button" x:Key="UndoButton" BasedOn="{StaticResource ActionButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Image Source="pack://application:,,,/Images/Undo.png" Height="16" Width="16" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="TextBox" x:Key="ValidatedTextBox">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsInvalid}" Value="True">
                    <Setter Property="Background" Value="Red" />
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <ToolTip>
                                <ItemsControl ItemsSource="{Binding ValidationErrors}" DisplayMemberPath="ErrorDescription" />
                            </ToolTip>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Application.Resources>
</Application>
